/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pluginPanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import pluginFonctions.FunctionProcessor;

/**
 *
 * @author mazid
 */
public class PanelHaut implements ActionListener{
    
    private JLabel label ;
    private JButton fonction, valider;
    private static JTextField editor;
    private JPanel panel;
    
    private static String nameFonction;
    private static ArrayList<Double> valeurs;
    
    public PanelHaut(){
       
    }
    
    public JPanel addPanel(){
        panel = new JPanel();
        label = new JLabel("place du JCombo box");
        valider = new JButton("OK");
        valider.setActionCommand("valider");
        valider.addActionListener(this);
        fonction = new JButton("Fonction");
        fonction.addActionListener(this);
        fonction.setActionCommand("fonction");
        editor = new JTextField(30);
        editor.addActionListener(this);
        editor.setActionCommand("formule");
        panel.add(label);
        panel.add(fonction);
        panel.add(editor);
        panel.add(valider);
        
        return panel;
    }

    public JLabel getLabel() {
        return label;
    }

    public JTextField getEditor() {
        return editor;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("valider")){
            FunctionProcessor fp = new FunctionProcessor();
            double db = fp.calculer(nameFonction, valeurs);
            System.out.println("le resultat est "+db);
            System.out.println(editor.getText());
        }
        if(e.getActionCommand().equals("fonction")){
            new MiniFrame();
            
            
        }
    }

    public static ArrayList<Double> getValeurs() {
        return valeurs;
    }

    public static void setValeurs(ArrayList<Double> valeurs) {
        PanelHaut.valeurs = valeurs;
    }

    public String getNameFonction() {
        return nameFonction;
    }

    public static void setNameFonction(String nameFonction) {
        PanelHaut.nameFonction = nameFonction;
        editor.setText("="+nameFonction+"()");
    }
    
}
